home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / AIncludes / Math64.a < prev    next >
Encoding:
Text File  |  1998-02-12  |  11.9 KB  |  494 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        Math64.a
  3. ;
  4. ;    Contains:    64-bit integer math Interfaces.
  5. ;
  6. ;    Version:    Technology:    System 7.5
  7. ;                Release:    Universal Interfaces 3.1
  8. ;
  9. ;    Copyright:    © 1994-1998 by Apple Computer, Inc., all rights reserved
  10. ;
  11. ;    Bugs?:        Please include the the file and version information (from above) with
  12. ;                the problem description.  Developers belonging to one of the Apple
  13. ;                developer programs can submit bug reports to:
  14. ;
  15. ;                    devsupport@apple.com
  16. ;
  17. ;
  18.     IF &TYPE('__MATH64__') = 'UNDEFINED' THEN
  19. __MATH64__ SET 1
  20.  
  21.     IF &TYPE('__CONDITIONALMACROS__') = 'UNDEFINED' THEN
  22.     include 'ConditionalMacros.a'
  23.     ENDIF
  24.     IF &TYPE('__MACTYPES__') = 'UNDEFINED' THEN
  25.     include 'MacTypes.a'
  26.     ENDIF
  27.  
  28.  
  29. ; --------------------------------------------------------------------------------
  30. ;                These routines are intended to provide C software support for
  31. ;                64 bit integer types.  Their behavior should mimic anticipated
  32. ;                64 bit hardware. This implementation should replace use of the
  33. ;                "wide" type found in PowerPC.
  34. ;
  35. ;    The following routines are available for performing math on 64-bit integers:
  36. ;    
  37. ;    S64Max
  38. ;                Returns the largest representable SInt64.
  39. ;    S64Min
  40. ;                Returns the smallest (i.e. most negative) SInt64.  Note: the negative
  41. ;                (absolute value) of this number is not representable in an SInt64.
  42. ;                That means that S64Negate(S64Min) is not representable (in fact,
  43. ;                it returns S64Min).
  44. ;    S64Add
  45. ;                Adds two integers, producing an integer result.  If an overflow
  46. ;                occurs the result is congruent mod (2^64) as if the operands and
  47. ;                result were unsigned.  No overflow is signaled.
  48. ;    
  49. ;    S64Subtract
  50. ;                Subtracts two integers, producing an integer result.  If an overflow
  51. ;                occurs the result is congruent mod (2^64) as if the operands and
  52. ;                result were unsigned.  No overflow is signaled.
  53. ;
  54. ;    S64Negate
  55. ;                Returns the additive inverse of a signed number (i.e. it returns
  56. ;                0 - the number).  S64Negate (S64Min) is not representable (in fact,
  57. ;                it returns S64Min).
  58. ;    
  59. ;    S64Absolute
  60. ;                Returns the absolute value of the number (i.e. the number if
  61. ;                it is positive, or 0 - the number if it is negative).
  62. ;                See S64Negate above.
  63. ;                
  64. ;    S64Multiply
  65. ;                Multiplies two signed numbers, producing a signed result.  Overflow
  66. ;                is ignored and the low-order part of the product is returned.  The
  67. ;                sign of the result is not guaranteed to be correct if the magnitude
  68. ;                of the product is not representable.
  69. ;                
  70. ;    S64Div
  71. ;                Divides dividend by divisor, returning the quotient.  
  72. ;
  73. ;    S64Divide
  74. ;                Divides dividend by divisor, returning the quotient.  The remainder
  75. ;                is returned in *remainder if remainder (the pointer) is non-NULL.
  76. ;                The sign of the remainder is the same as the sign of the dividend
  77. ;                (i.e. it takes the absolute values of the operands, does the division,
  78. ;                then fixes the sign of the quotient and remainder).  If the divisor
  79. ;                is zero, then S64Max() will be returned (or S64Min() if the dividend
  80. ;                is negative), and the remainder will be the dividend; no error is
  81. ;                reported.
  82. ;    
  83. ;    S64Set
  84. ;                Given an SInt32, returns an SInt64 with the same value.  Use this
  85. ;                routine instead of coding 64-bit constants (at least when the
  86. ;                constant will fit in an SInt32).
  87. ;    
  88. ;    S64SetU
  89. ;                Given a UInt32, returns a SInt64 with the same value.
  90. ;    
  91. ;    S64Compare
  92. ;                Given two signed numbers, left and right, returns an
  93. ;                SInt32 that compares with zero the same way left compares with
  94. ;                right.  If you wanted to perform a comparison on 64-bit integers
  95. ;                of the form:
  96. ;                        operand_1 <operation> operand_2
  97. ;                then you could use an expression of the form:
  98. ;                        xxxS64Compare(operand_1,operand_2) <operation> 0
  99. ;                to test for the same condition.
  100. ;                
  101. ;                CAUTION: DO NOT depend on the exact value returned by this routine.
  102. ;                Only the sign (i.e. positive, zero, or negative) of the result is
  103. ;                guaranteed.
  104. ;
  105. ;    S64And, S64Or, S64Eor and S64Not
  106. ;    
  107. ;                Return Boolean (1 or 0) depending on the outcome of the logical
  108. ;                operation.
  109. ;
  110. ;    S64BitwiseAnd, S64BitwiseOr, S64BitwiseEor and S64BitwiseNot
  111. ;    
  112. ;                Return the Bitwise result.
  113. ;                
  114. ;    S64ShiftRight and S64ShiftLeft
  115. ;    
  116. ;                The lower 7 bits of the shift argument determines the amount of 
  117. ;                shifting.  S64ShiftRight is an arithmetic shift while U64ShiftRight
  118. ;                is a logical shift.
  119. ;
  120. ;    SInt64ToLongDouble
  121. ;                
  122. ;                Converts SInt64 to long double.  Note all SInt64s fit exactly into 
  123. ;                long doubles, thus, the binary -> decimal conversion routines
  124. ;                in fp.h can be used to achieve SInt64 -> long double -> decimal
  125. ;                conversions.
  126. ;                
  127. ;    LongDoubleToSInt64
  128. ;    
  129. ;                Converts a long double to a SInt64.  Any decimal string that fits
  130. ;                into a SInt64 can be converted exactly into a long double, using the
  131. ;                conversion routines found in fp.h.  Then this routine can be used
  132. ;                to complete the conversion to SInt64.
  133. ;                
  134. ;    SInt64ToWide
  135. ;    
  136. ;                Converts a SInt64 to a wide struct.  If SInt64 is implemented
  137. ;                as a typedef of wide, the marco does nothing. If SInt64 is 
  138. ;                implememnted as a long long, it casts the long long into a 
  139. ;                wide struct.
  140. ;    
  141. ;    WideToSInt64
  142. ;    
  143. ;                Converts a wide struct into a SInt64.  If SInt64 is implemented
  144. ;                as a typedef of wide, the marco does nothing. If SInt64 is 
  145. ;                implememnted as a long long, it reads the struct into a long long.
  146. ;    
  147. ;    
  148. ;    The corresponding UInt64 routines are also included.
  149. ;    
  150. ;--------------------------------------------------------------------------------
  151.  
  152.  
  153. ;
  154. ; extern SInt64 S64Max(void )
  155. ;
  156.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  157.         IMPORT_CFM_FUNCTION S64Max
  158.     ENDIF
  159.  
  160. ;
  161. ; extern SInt64 S64Min(void )
  162. ;
  163.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  164.         IMPORT_CFM_FUNCTION S64Min
  165.     ENDIF
  166.  
  167. ;
  168. ; extern SInt64 S64Add(SInt64 x, SInt64 y)
  169. ;
  170.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  171.         IMPORT_CFM_FUNCTION S64Add
  172.     ENDIF
  173.  
  174. ;
  175. ; extern SInt64 S64Subtract(SInt64 left, SInt64 right)
  176. ;
  177.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  178.         IMPORT_CFM_FUNCTION S64Subtract
  179.     ENDIF
  180.  
  181. ;
  182. ; extern SInt64 S64Negate(SInt64 value)
  183. ;
  184.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  185.         IMPORT_CFM_FUNCTION S64Negate
  186.     ENDIF
  187.  
  188. ;
  189. ; extern SInt64 S64Absolute(SInt64 value)
  190. ;
  191.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  192.         IMPORT_CFM_FUNCTION S64Absolute
  193.     ENDIF
  194.  
  195. ;
  196. ; extern SInt64 S64Multiply(SInt64 xparam, SInt64 yparam)
  197. ;
  198.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  199.         IMPORT_CFM_FUNCTION S64Multiply
  200.     ENDIF
  201.  
  202. ;
  203. ; extern SInt64 S64Divide(SInt64 dividend, SInt64 divisor, SInt64 *remainder)
  204. ;
  205.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  206.         IMPORT_CFM_FUNCTION S64Divide
  207.     ENDIF
  208.  
  209. ;
  210. ; extern SInt64 S64Set(SInt32 value)
  211. ;
  212.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  213.         IMPORT_CFM_FUNCTION S64Set
  214.     ENDIF
  215.  
  216. ;
  217. ; extern SInt64 S64SetU(UInt32 value)
  218. ;
  219.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  220.         IMPORT_CFM_FUNCTION S64SetU
  221.     ENDIF
  222.  
  223. ;
  224. ; extern SInt32 S32Set(SInt64 value)
  225. ;
  226.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  227.         IMPORT_CFM_FUNCTION S32Set
  228.     ENDIF
  229.  
  230. ;
  231. ; extern int S64Compare(SInt64 left, SInt64 right)
  232. ;
  233.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  234.         IMPORT_CFM_FUNCTION S64Compare
  235.     ENDIF
  236.  
  237. ;
  238. ; extern Boolean S64And(SInt64 left, SInt64 right)
  239. ;
  240.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  241.         IMPORT_CFM_FUNCTION S64And
  242.     ENDIF
  243.  
  244. ;
  245. ; extern Boolean S64Or(SInt64 left, SInt64 right)
  246. ;
  247.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  248.         IMPORT_CFM_FUNCTION S64Or
  249.     ENDIF
  250.  
  251. ;
  252. ; extern Boolean S64Eor(SInt64 left, SInt64 right)
  253. ;
  254.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  255.         IMPORT_CFM_FUNCTION S64Eor
  256.     ENDIF
  257.  
  258. ;
  259. ; extern Boolean S64Not(SInt64 value)
  260. ;
  261.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  262.         IMPORT_CFM_FUNCTION S64Not
  263.     ENDIF
  264.  
  265. ;
  266. ; extern SInt64 S64BitwiseAnd(SInt64 left, SInt64 right)
  267. ;
  268.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  269.         IMPORT_CFM_FUNCTION S64BitwiseAnd
  270.     ENDIF
  271.  
  272. ;
  273. ; extern SInt64 S64BitwiseOr(SInt64 left, SInt64 right)
  274. ;
  275.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  276.         IMPORT_CFM_FUNCTION S64BitwiseOr
  277.     ENDIF
  278.  
  279. ;
  280. ; extern SInt64 S64BitwiseEor(SInt64 left, SInt64 right)
  281. ;
  282.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  283.         IMPORT_CFM_FUNCTION S64BitwiseEor
  284.     ENDIF
  285.  
  286. ;
  287. ; extern SInt64 S64BitwiseNot(SInt64 value)
  288. ;
  289.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  290.         IMPORT_CFM_FUNCTION S64BitwiseNot
  291.     ENDIF
  292.  
  293. ;
  294. ; extern SInt64 S64ShiftRight(SInt64 value, UInt32 shift)
  295. ;
  296.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  297.         IMPORT_CFM_FUNCTION S64ShiftRight
  298.     ENDIF
  299.  
  300. ;
  301. ; extern SInt64 S64ShiftLeft(SInt64 value, UInt32 shift)
  302. ;
  303.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  304.         IMPORT_CFM_FUNCTION S64ShiftLeft
  305.     ENDIF
  306.  
  307. ;    "long double" means 128 bit type on PowerPC and 80-bit type on 68K
  308. ;
  309.  
  310. ;
  311. ; extern long double SInt64ToLongDouble(SInt64 value)
  312. ;
  313.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  314.         IMPORT_CFM_FUNCTION SInt64ToLongDouble
  315.     ENDIF
  316.  
  317. ;
  318. ; extern SInt64 LongDoubleToSInt64(long double value)
  319. ;
  320.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  321.         IMPORT_CFM_FUNCTION LongDoubleToSInt64
  322.     ENDIF
  323.  
  324. ;
  325. ; extern UInt64 U64Max(void )
  326. ;
  327.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  328.         IMPORT_CFM_FUNCTION U64Max
  329.     ENDIF
  330.  
  331. ;
  332. ; extern UInt64 U64Add(UInt64 x, UInt64 y)
  333. ;
  334.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  335.         IMPORT_CFM_FUNCTION U64Add
  336.     ENDIF
  337.  
  338. ;
  339. ; extern UInt64 U64Subtract(UInt64 left, UInt64 right)
  340. ;
  341.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  342.         IMPORT_CFM_FUNCTION U64Subtract
  343.     ENDIF
  344.  
  345. ;
  346. ; extern UInt64 U64Multiply(UInt64 xparam, UInt64 yparam)
  347. ;
  348.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  349.         IMPORT_CFM_FUNCTION U64Multiply
  350.     ENDIF
  351.  
  352. ;
  353. ; extern UInt64 U64Divide(UInt64 dividend, UInt64 divisor, UInt64 *remainder)
  354. ;
  355.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  356.         IMPORT_CFM_FUNCTION U64Divide
  357.     ENDIF
  358.  
  359. ;
  360. ; extern UInt64 U64Set(SInt32 value)
  361. ;
  362.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  363.         IMPORT_CFM_FUNCTION U64Set
  364.     ENDIF
  365.  
  366. ;
  367. ; extern UInt64 U64SetU(UInt32 value)
  368. ;
  369.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  370.         IMPORT_CFM_FUNCTION U64SetU
  371.     ENDIF
  372.  
  373. ;
  374. ; extern UInt32 U32SetU(UInt64 value)
  375. ;
  376.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  377.         IMPORT_CFM_FUNCTION U32SetU
  378.     ENDIF
  379.  
  380. ;
  381. ; extern int U64Compare(UInt64 left, UInt64 right)
  382. ;
  383.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  384.         IMPORT_CFM_FUNCTION U64Compare
  385.     ENDIF
  386.  
  387. ;
  388. ; extern Boolean U64And(UInt64 left, UInt64 right)
  389. ;
  390.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  391.         IMPORT_CFM_FUNCTION U64And
  392.     ENDIF
  393.  
  394. ;
  395. ; extern Boolean U64Or(UInt64 left, UInt64 right)
  396. ;
  397.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  398.         IMPORT_CFM_FUNCTION U64Or
  399.     ENDIF
  400.  
  401. ;
  402. ; extern Boolean U64Eor(UInt64 left, UInt64 right)
  403. ;
  404.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  405.         IMPORT_CFM_FUNCTION U64Eor
  406.     ENDIF
  407.  
  408. ;
  409. ; extern Boolean U64Not(UInt64 value)
  410. ;
  411.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  412.         IMPORT_CFM_FUNCTION U64Not
  413.     ENDIF
  414.  
  415. ;
  416. ; extern UInt64 U64BitwiseAnd(UInt64 left, UInt64 right)
  417. ;
  418.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  419.         IMPORT_CFM_FUNCTION U64BitwiseAnd
  420.     ENDIF
  421.  
  422. ;
  423. ; extern UInt64 U64BitwiseOr(UInt64 left, UInt64 right)
  424. ;
  425.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  426.         IMPORT_CFM_FUNCTION U64BitwiseOr
  427.     ENDIF
  428.  
  429. ;
  430. ; extern UInt64 U64BitwiseEor(UInt64 left, UInt64 right)
  431. ;
  432.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  433.         IMPORT_CFM_FUNCTION U64BitwiseEor
  434.     ENDIF
  435.  
  436. ;
  437. ; extern UInt64 U64BitwiseNot(UInt64 value)
  438. ;
  439.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  440.         IMPORT_CFM_FUNCTION U64BitwiseNot
  441.     ENDIF
  442.  
  443. ;
  444. ; extern UInt64 U64ShiftRight(UInt64 value, UInt32 shift)
  445. ;
  446.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  447.         IMPORT_CFM_FUNCTION U64ShiftRight
  448.     ENDIF
  449.  
  450. ;
  451. ; extern UInt64 U64ShiftLeft(UInt64 value, UInt32 shift)
  452. ;
  453.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  454.         IMPORT_CFM_FUNCTION U64ShiftLeft
  455.     ENDIF
  456.  
  457. ;    "long double" means 128 bit type on PowerPC and 80-bit type on 68K
  458. ;
  459.  
  460. ;
  461. ; extern long double UInt64ToLongDouble(UInt64 value)
  462. ;
  463.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  464.         IMPORT_CFM_FUNCTION UInt64ToLongDouble
  465.     ENDIF
  466.  
  467. ;
  468. ; extern UInt64 LongDoubleToUInt64(long double value)
  469. ;
  470.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  471.         IMPORT_CFM_FUNCTION LongDoubleToUInt64
  472.     ENDIF
  473.  
  474. ;
  475. ; extern SInt64 UInt64ToSInt64(UInt64 value)
  476. ;
  477.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  478.         IMPORT_CFM_FUNCTION UInt64ToSInt64
  479.     ENDIF
  480.  
  481. ;
  482. ; extern UInt64 SInt64ToUInt64(SInt64 value)
  483. ;
  484.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  485.         IMPORT_CFM_FUNCTION SInt64ToUInt64
  486.     ENDIF
  487.  
  488.  
  489.  
  490.     ENDIF ; __MATH64__ 
  491.  
  492.